package com.sskj.level.presenter;

import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.level.bean.TradeInfoBean;
import com.sskj.level.bean.TradeListBean;
import com.sskj.level.http.HttpConfig;
import com.sskj.level.ui.activity.TradeActivity;
import com.sskj.lib.RxBusCode;
import com.sskj.lib.bean.PageBean;
import com.sskj.lib.box.LiveDataBus;
import com.sskj.lib.http.CallBackOption;


public class TradeActivityPresenter extends BasePresenter<TradeActivity> {

    public void getRisk() {
        httpService.getTradeInfo()
                .execute(new CallBackOption<HttpData<TradeInfoBean>>() {
                }.unLoadBind(mView)
                .execute(httpData-> mView.updateTrade(httpData.getData())));
    }

    /**
     * 一键平仓
     */
    public void levelAllPc(String stockCode) {
        httpService.levelAllPc(stockCode)
                .execute(new CallBackOption<HttpData>() {
                }
                        .unLoadBind(mView)
                        .execute(httpData -> {
                            if (httpData.getStatus() == HttpConfig.OK) {
                                ToastUtil.showShort(httpData.getMsg());
                                LiveDataBus.get().with(RxBusCode.LEVEL_ALL_PC).postValue(1);
                            }
                        }));
    }

    public void getAllList() {
        httpService.getChiCang(null, null, null)
                .execute(new CallBackOption<HttpData<PageBean<TradeListBean>>>() {
                }.unLoadBind(mView)
                        .execute(httpData -> {
                            mView.updateUI(httpData.getData().getList());
                        }));
    }
}
